using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace AstroX
{
    public delegate void WaterDetectedHandler();
    public class WaterSensor
    {
        InterruptPort i = new InterruptPort(AstoXPinMap.WaterSensor, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelLow);
        public WaterSensor()
        {
            //i.OnInterrupt += new NativeEventHandler(i_OnInterrupt);
        }

        void i_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (data2 == 0)
            {
                if (WaterDetected != null)
                {
                    WaterDetected();
                }
            }
        }

        public bool IsWaterPresent
        {
            get { return !i.Read(); }
        }

        public event WaterDetectedHandler WaterDetected = null;
    }
}
